package com.yuntu.micor.app.controller;

import com.yuntu.micor.app.entity.ResponseData;
import com.yuntu.micor.app.entity.XhVersion;
import com.yuntu.micor.app.service.IVersionService;
import com.yuntu.micor.app.util.DateUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/version")
@RequiredArgsConstructor
public class VserionController {

    private final IVersionService versionService;


    @GetMapping()
    public ModelAndView getVersion() {
        ModelAndView mv = new ModelAndView();
        List<XhVersion> xhVersionList = versionService.list();
        mv.addObject("list", xhVersionList);
        mv.setViewName("model");
        return mv;
    }

    @GetMapping("add")
    @ResponseBody
    public ResponseData<XhVersion> addVersion() {
        XhVersion version = new XhVersion();
        version.setVersionRe(DateUtils.getDateTime());
        version.setVersionBuild("yuntu");
        versionService.save(version);
        return ResponseData.ok(version);
    }

    @GetMapping("page")
    @ResponseBody
    public ResponseData<List<XhVersion>> addVersion(long current, long pageSize) {
        return ResponseData.page(versionService.queryByPage(current,pageSize ));
    }
}
